package com.hmdz.commons.utils;

public final class NumberUtils {

    /**
     * 判斷是否為奇數
     * @param num
     * @return
     */
    public static boolean isOddNumber(long num) {
        return (num & 1) == 1;
    }

    /**
     * 交換數據
     * @param a
     * @param b
     */
    public static void swap(Long a, Long b) {
        a = a ^ b;
        b = a ^ b;
        a = a ^ b;
    }

    public static int pow(int n){
        int sum = 1;
        int tmp = 3;
        while(n != 0){
            if((n & 1) == 1){
                sum *= tmp;
            }
            tmp *= tmp;
            n = n >> 1;
        }
        return sum;
    }

    public static int findN(int n){
        n |= n >> 1;
        n |= n >> 2;
        n |= n >> 4;
        n |= n >> 8; // 整型一般是 32 位，上面我是假设 8 位。
        return (n + 1) >> 1;
    }

    public static void main(String[] args) {
        System.out.println(pow(13));//1594323
        System.out.println(findN(15));
    }
}
